package.cpath = "luaclib/?.so"

if _VERSION ~= "Lua 5.4" then
    error "Use lua 5.4"
end

local xxtea      = require "xxtea"


local function strToHex(str)
    return (str:gsub(".", function(char) return string.format("%02x", char:byte()) end))
end


local function hexToStr(hex)
    return (hex:gsub("%x%x", function(digits) return string.char(tonumber(digits, 16)) end))
end

local function getOS()
    return "LIN"
end

local function getSerialNum()
    local os = getOS()
    if os == "LIN" then
        local e = io.popen(" dmidecode -t 4 | grep ID |sort -u |awk -F': ' '{print $2}' ")
        local s = e:read("*all")
        e:close()
        return string.lower(string.gsub(s, "%s+", ""))
    else
        error "该系统还未实现"
    end
end

local function showkey()
    local serialNum = getSerialNum()
    print("机器码 = ", serialNum, "\n")
    local b = xxtea.encrypt(serialNum, "s52cv*%(O")
    local c = strToHex(b);
    print("当前系统的key为:", c);
end

showkey()